package com.ruoyi.zsyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhAgentAddress;
import com.ruoyi.zsyh.service.IZsyhAgentAddressService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 大区会长收货地址Controller
 * 
 * @author yuexl
 * @date 2021-12-14
 */
@Controller
@RequestMapping("/zsyh/agentaddress")
public class ZsyhAgentAddressController extends BaseController
{
    private String prefix = "zsyh/agentaddress";

    @Autowired
    private IZsyhAgentAddressService zsyhAgentAddressService;

    @RequiresPermissions("zsyh:agentaddress:view")
    @GetMapping()
    public String agentaddress()
    {
        return prefix + "/agentaddress";
    }

    /**
     * 修改大区会长收货地址
     */
    @GetMapping("/view/{id}")
    public String view(@PathVariable("id") String id, ModelMap mmap)
    {
        mmap.put("agentId", id);
        return prefix + "/viewAddress";
    }

    /**
     * 查询大区会长收货地址列表
     */
    @RequiresPermissions("zsyh:agentaddress:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhAgentAddress zsyhAgentAddress)
    {
        startPage();
        List<ZsyhAgentAddress> list = zsyhAgentAddressService.selectZsyhAgentAddressList(zsyhAgentAddress);
        return getDataTable(list);
    }

    /**
     * 查询大区会长收货地址列表
     */
    @RequiresPermissions("zsyh:agentaddress:list")
    @PostMapping("/listDetail")
    @ResponseBody
    public TableDataInfo listDetail(ZsyhAgentAddress zsyhAgentAddress)
    {
        startPage();
        List<ZsyhAgentAddress> list = zsyhAgentAddressService.selectZsyhAgentAddressList(zsyhAgentAddress);
        return getDataTable(list);
    }

    /**
     * 导出大区会长收货地址列表
     */
    @RequiresPermissions("zsyh:agentaddress:export")
    @Log(title = "大区会长收货地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhAgentAddress zsyhAgentAddress)
    {
        List<ZsyhAgentAddress> list = zsyhAgentAddressService.selectZsyhAgentAddressList(zsyhAgentAddress);
        ExcelUtil<ZsyhAgentAddress> util = new ExcelUtil<ZsyhAgentAddress>(ZsyhAgentAddress.class);
        return util.exportExcel(list, "大区会长收货地址数据");
    }

    /**
     * 新增大区会长收货地址
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存大区会长收货地址
     */
    @RequiresPermissions("zsyh:agentaddress:add")
    @Log(title = "大区会长收货地址", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhAgentAddress zsyhAgentAddress)
    {
        return toAjax(zsyhAgentAddressService.insertZsyhAgentAddress(zsyhAgentAddress));
    }

    /**
     * 修改大区会长收货地址
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhAgentAddress zsyhAgentAddress = zsyhAgentAddressService.selectZsyhAgentAddressById(id);
        mmap.put("zsyhAgentAddress", zsyhAgentAddress);
        return prefix + "/edit";
    }

    /**
     * 修改保存大区会长收货地址
     */
    @RequiresPermissions("zsyh:agentaddress:edit")
    @Log(title = "大区会长收货地址", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhAgentAddress zsyhAgentAddress)
    {
        return toAjax(zsyhAgentAddressService.updateZsyhAgentAddress(zsyhAgentAddress));
    }

    /**
     * 删除大区会长收货地址
     */
    @RequiresPermissions("zsyh:agentaddress:remove")
    @Log(title = "大区会长收货地址", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhAgentAddressService.deleteZsyhAgentAddressByIds(ids));
    }
}
